<#assign className = table.className>
<#assign classNameLower = className?uncap_first>
package ${basePackage}.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import ${basePackage}.utils.PageUtil;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.PathVariable;

import ${basePackage}.vo.${table.classNameLower}.${table.className}SelectQueryRequestVo;
import ${basePackage}.vo.${table.classNameLower}.${table.className}FindQueryRequestVo;
import ${basePackage}.vo.${table.classNameLower}.${table.className}InsertRequestVo;
import ${basePackage}.vo.${table.classNameLower}.${table.className}UpdateRequestVo;
import ${basePackage}.vo.${table.classNameLower}.${table.className}DeleteRequestVo;
import ${basePackage}.vo.${table.classNameLower}.${table.className}SelectQueryResponseVo;
import ${basePackage}.vo.${table.classNameLower}.${table.className}FindQueryResponseVo;

import ${basePackage}.dto.${table.classNameLower}.${table.className}SelectQueryRequestDto;
import ${basePackage}.dto.${table.classNameLower}.${table.className}FindQueryRequestDto;
import ${basePackage}.dto.${table.classNameLower}.${table.className}InsertRequestDto;
import ${basePackage}.dto.${table.classNameLower}.${table.className}DeleteRequestDto;
import ${basePackage}.dto.${table.classNameLower}.${table.className}UpdateRequestDto;
import ${basePackage}.dto.${table.classNameLower}.${table.className}FindQueryResponseDto;
import ${basePackage}.dto.${table.classNameLower}.${table.className}SelectQueryResponseDto;

import ${basePackage}.framework.object.ResponseVo;
import ${basePackage}.service.${table.className}Service;
import ${basePackage}.converter.${table.className}Converter;
import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * ${table.remark} 控制器层
 * </p>
 *
 * @author wangjin
 * @classname: ${className}
 * @description: ${table.remark} 控制器层
 * @towork: none
 * @version: 1.0.0
 * @since ${.now?string('yyyy/MM/dd HH:mm')}
 */
@RestController
@RequestMapping("/admin/${table.classNameFirstLower}")
public class ${table.className}AdminController {
    /**
     * ${table.remark} 服务层实例化对象
     */
    @Resource
    ${table.className}Service ${table.className?uncap_first}Service;

    /**
    * ${table.remark} pojo转换器
    */
    @Resource
    ${table.className}Converter ${table.className?uncap_first}Converter;

    /**
     * ${table.remark} 列表查询
     *
     * @param ${table.className?uncap_first}SelectQueryRequestVo ${table.remark} 查询数据请求封装对象
     * @return ${table.className} 集合
     */
    @PostMapping("/selectList")
    public   ResponseVo<PageInfo<${table.className}SelectQueryResponseVo>> selectList(@RequestBody ${table.className}SelectQueryRequestVo ${table.className?uncap_first}SelectQueryRequestVo){
        //将vo转换成dto
        ${table.className}SelectQueryRequestDto ${table.className?uncap_first}SelectQueryRequestDto =  ${table.className?uncap_first}Converter.selectQueryRequestVoToDto(${table.className?uncap_first}SelectQueryRequestVo);

        //分页查询
        Page                                    page = PageHelper.startPage(${table.className?uncap_first}SelectQueryRequestVo.getPageNum(), ${table.className?uncap_first}SelectQueryRequestVo.getPageSize());
        List<${table.className}SelectQueryResponseDto> ${table.className}SelectQueryResponseDtoList = ${table.className?uncap_first}Service.selectList(${table.className?uncap_first}SelectQueryRequestDto);

        //处理返回结果
        List<${table.className}SelectQueryResponseVo> list = ${table.className?uncap_first}Converter.selectQueryResponseDtoToVo(${table.className}SelectQueryResponseDtoList);
        PageInfo<${table.className}SelectQueryResponseVo> pageInfo = new PageInfo<>(list);
        PageUtil.pageToInfo(pageInfo,page);//处理转换结果数据导致分页不准确的情况
        return ResponseVo.success(pageInfo);
    }

    /**
     * ${table.remark} 根据主键查询数据
     <#list table.columns as field>
     <#if field.keyType == "PRI">* @param ${field.columnNameFirstLower} ${table.remark} 主键</#if>
     </#list>
     * @return ${table.className}FindQueryResponseDto
     */
    @GetMapping("/find<#list table.columns as field><#if field.keyType == "PRI">/{${field.columnNameFirstLower}}</#if></#list>")
    public ResponseVo<${table.className}FindQueryResponseVo> findByPrimaryKey(<#list table.columns as field><#if field.keyType == "PRI"><#if field_index == 0>@PathVariable("${field.columnNameFirstLower}") Integer ${field.columnNameFirstLower}<#else>,@PathVariable("${field.columnNameFirstLower}") Integer ${field.columnNameFirstLower}</#if></#if></#list>){
        //封装成dto对象
        ${table.className}FindQueryRequestDto ${table.className?uncap_first}FindQueryRequestDto = ${table.className}FindQueryRequestDto.builder()
        <#list table.columns as field><#if field.keyType == "PRI">.${field.columnNameFirstLower}(${field.columnNameFirstLower})</#if></#list>.build();

        //执行逻辑
        ${table.className}FindQueryResponseDto ${table.className?uncap_first}FindQueryResponseDto = ${table.className?uncap_first}Service.findByPrimaryKey(${table.className?uncap_first}FindQueryRequestDto);

        //处理返回结果
        ${table.className}FindQueryResponseVo ${table.className?uncap_first}FindQueryResponseVo =  ${table.className?uncap_first}Converter.findQueryResponseDtoToVo(${table.className?uncap_first}FindQueryResponseDto);

        //数据返回前端
        return ResponseVo.success(${table.className?uncap_first}FindQueryResponseVo);
    }

    /**
     * ${table.remark} 新增
     *
     * @param ${table.className?uncap_first}InsertRequestVo ${table.remark} 插入数据请求封装对象
     * @return 受影响行数
     */
    @PutMapping("/insert")
    public ResponseVo insert(@RequestBody ${table.className}InsertRequestVo ${table.className?uncap_first}InsertRequestVo){
        //将vo转换成dto
        ${table.className}InsertRequestDto ${table.className?uncap_first}InsertRequestDto =  ${table.className?uncap_first}Converter.insertRequestVoToDto(${table.className?uncap_first}InsertRequestVo);

        //执行逻辑
        int res = ${table.className?uncap_first}Service.insert(${table.className?uncap_first}InsertRequestDto);

        //处理结果
        if(res>0){
            return ResponseVo.success();
        }else{
            return ResponseVo.error();
        }
    }

    /**
     * ${table.remark} 根据主键更新
     *
     * @param ${table.className?uncap_first}UpdateRequestVo ${table.remark}更新数据请求封装对象
     * @return 受影响行数
     */
    @PutMapping("/update")
    public ResponseVo updateByPrimaryKey(@RequestBody ${table.className}UpdateRequestVo ${table.className?uncap_first}UpdateRequestVo){
        //将vo转换成dto
        ${table.className}UpdateRequestDto ${table.className?uncap_first}UpdateRequestDto =  ${table.className?uncap_first}Converter.updateRequestVoToDto(${table.className?uncap_first}UpdateRequestVo);

        //执行逻辑
        int res = ${table.className?uncap_first}Service.updateByPrimaryKey(${table.className?uncap_first}UpdateRequestDto);

        //处理结果
        if(res>0){
        return ResponseVo.success();
        }else{
        return ResponseVo.error();
        }
    }

    /**
     * ${table.remark} 根据主键删除
     *
     * @param ${table.className?uncap_first}DeleteRequestVo ${table.remark}删除数据请求封装对象
     * @return 受影响行数
     */
    @PutMapping("/delete")
    public ResponseVo updateByPrimaryKey(@RequestBody ${table.className}DeleteRequestVo ${table.className?uncap_first}DeleteRequestVo){
        //将vo转换成dto
        ${table.className}DeleteRequestDto ${table.className?uncap_first}DeleteRequestDto =  ${table.className?uncap_first}Converter.deleteRequestVoToDto(${table.className?uncap_first}DeleteRequestVo);

        //执行逻辑
        int res = ${table.className?uncap_first}Service.delete(${table.className?uncap_first}DeleteRequestDto);

        //处理结果
        if(res>0){
        return ResponseVo.success();
        }else{
        return ResponseVo.error();
        }
    }

    /**
     * ${table.remark} 根据主键批量删除
     *
     * @param ${table.className?uncap_first}DeleteRequestVoList ${table.remark}批量删除数据请求封装对象
     * @return 受影响行数
     */
    @PutMapping("/deleteByBatch")
    public ResponseVo updateByPrimaryKey(@RequestBody List<${table.className}DeleteRequestVo> ${table.className?uncap_first}DeleteRequestVoList){
        //将vo转换成dto
        List<${table.className}DeleteRequestDto> ${table.className?uncap_first}DeleteRequestDtoList =  ${table.className?uncap_first}Converter.deleteRequestVoToDtoByBatch(${table.className?uncap_first}DeleteRequestVoList);

        //执行逻辑
        int res = ${table.className?uncap_first}Service.deleteByBatch(${table.className?uncap_first}DeleteRequestDtoList);

        //处理结果
        if(res>0){
        return ResponseVo.success();
        }else{
        return ResponseVo.error();
        }
        }
    }